package com.coffee.soft.service.impl;

import com.coffee.soft.entity.Items;
import com.coffee.soft.entity.ItemsCarousel;
import com.coffee.soft.mapper.ItemsMapper;
import com.coffee.soft.service.ItemsManangerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author:LiuRuidong
 * @Description: 商品后台管理的实现类
 * @Date: Created in 9:42 2018/2/5
 * @Modified By:
 */
@Service
public class ItemsManagerServiceImpl implements ItemsManangerService {
    @Autowired
    private ItemsMapper itemsMapper;
/**
 * @Author：LiuRuidong
 * @Description: 选择未轮播的商品
 * @Date:2018/2/5 9:45
 * @Param:
 * @return
 */
    @Override
    public List<ItemsCarousel> selectNotCarousel() {
//      创建存储非轮播图的图片
        List<ItemsCarousel> itemsCarousels = new ArrayList();
//       查询出来的所有商品
        List<Items> itemsList = itemsMapper.selectNotCarousel();
//        迭代所有查询出来的东西
        ItemsCarousel itemsCarousel = null;
        Iterator<Items> iterator = itemsList.iterator();
        while(iterator.hasNext()){
            itemsCarousel = new ItemsCarousel();
            Items items = iterator.next();
            itemsCarousel.setItemsId(items.getItemsId());
            itemsCarousel.setCarouselPicture(items.getCarouselPicture());
            itemsCarousels.add(itemsCarousel);
        }
        return itemsCarousels;
    }
/**
 * @Author：LiuRuidong
 * @Description: 查询非新产品
 * @Date:2018/2/5 10:05
 * @Param:
 * @return
 */
    @Override
    public List<ItemsCarousel> selectNotNew() {
        //      创建存储非新品的图片
        List<ItemsCarousel> itemsNotNew = new ArrayList();
//       查询出来的所有商品
        List<Items> itemsList = itemsMapper.selectNotNewImage();
//        迭代所有查询出来的东西
        ItemsCarousel itemsCarousel = null;
        Iterator<Items> iterator = itemsList.iterator();
        while(iterator.hasNext()){
            itemsCarousel = new ItemsCarousel();
            Items items = iterator.next();
            itemsCarousel.setItemsId(items.getItemsId());
            itemsCarousel.setCarouselPicture(items.getCarouselPicture());
            itemsNotNew.add(itemsCarousel);
        }
        return itemsNotNew;
    }
/**
 * @Author：LiuRuidong
 * @Description: 选择更新轮播的属性
 * @Date:2018/2/5 10:25
 * @Param:
 * @return
 */
    @Override
    public int chooseCarousel(String itemsId) {
       int i = itemsMapper.updateChooseCarouselItems(itemsId);
       return i;
    }
/**
 * @Author：LiuRuidong
 * @Description: 选择更新新的图片的属性
 * @Date:2018/2/5 10:27
 * @Param:
 * @return
 */
    @Override
    public int chooseNew(String itemsId) {
        int result = itemsMapper.updateChooseNewItems(itemsId);
        return result;
    }
/**
 * @Author：LiuRuidong
 * @Description: 确认更新轮播的图片
 * @Date:2018/2/5 10:27
 * @Param:
 * @return
 */
    @Override
    public int confirmCarousel(String itemsId) {
       int i = itemsMapper.updateConfirmCarouselItems(itemsId);
        return i;
    }
/**
 * @Author：LiuRuidong
 * @Description: 确认更新新的图片
 * @Date:2018/2/5 10:28
 * @Param:
 * @return
 */
    @Override
    public int confirmNew(String itemsId) {
        int result = itemsMapper.updateConfirmNewItems(itemsId);
        return result;
    }
}
